import OrderStatusTpl from './install-order-status.html';

import './order-status.scss';

export default function OrderStatus($parent,status) {
    const orderStatus = [{
            text: '分部已收单',
            name: 'BRANCH_RECEIVE',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '已派一级网点',
            name: 'FIRST_STATION_ASSIGNED',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '一级网点接单',
            name: 'FIRST_STATION_ACCEPT',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '一级网点拒单',
            name: 'FIRST_STATION_REFUSE',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '已派二级网点',
            name: 'SECOND_STATION_ASSIGNED',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '二级网点接单',
            name: 'SECOND_STATION_ACCEPT',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '二级网点拒单',
            name: 'SECOND_STATION_REFUSE',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '已派师傅',
            name: 'WORKER_ASSIGNED',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '准备安装',
            name: 'WILL_INSTALL',
            position: 'normal',
            status: 'willExecute'
        },{
            text: '安装中',
            name: 'INSTALLING',
            position: 'installing',
            status: 'willExecute'
        },{
            text: '安装完成',
            name: 'INSTALL_FINISH',
            position: 'installing',
            status: 'willExecute'
        },{
            text: '评价完成',
            name: 'EVALUATE_FINISH',
            position: 'installing',
            status: 'willExecute'
        },{
            text: '回执完成',
            name: 'RECEIPT_FINISH',
            position: 'installing',
            status: 'willExecute'
        },{
            text: '无法安装',
            name: 'CAN_NOT_INSTALL',
            position: 'can-not-install',
            status: 'willExecute'
        },{
            text: '网点审核',
            name: 'STATION_CHECK',
            position: 'can-not-install',
            status: 'willExecute'
        },{
            text: '分部审核',
            name: 'BRANCH_CHECK',
            position: 'can-not-install',
            status: 'willExecute'
        },{
            text: '已取消',
            name: 'CANCEL',
            position: 'can-not-install',
            status: 'willExecute'
        }];

    let executed = true, boundary = 8, last = 4, idx = 0;
            
    orderStatus.map((item,index) => {
        if(item.name == status){
            item.status = 'executing';   
            idx = index;         
            if(index > (boundary + last)) {
                for(let i = boundary + 1; i <= boundary + last; i ++) {
                    orderStatus[i].status = 'willExecute';
                }
            }
            executed = false;
            return;
        }
        executed && (item.status = 'executed');
    });
    $parent.html( OrderStatusTpl({orderStatus, boundary, last, idx}) );
}